let tableIns;
let tree;
layui.use(['element', 'form', 'layer'], function () {
    let form = layui.form;//select、单选、复选等依赖form
    let element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
    
    $.post('/seller/sellerlist/list', {}, function (data) {
        var $html = "";
        if(data.data != null){
            $.each(data.data, function (index, item) {
            	if(item.serviceName != null && item.refState == 'Y'){
            		$html += "<option value='" + item.sellerId + "'>" + item.sellerName +'&nbsp;&nbsp;&nbsp;手机号:'+item.sellerMobile+'&nbsp;&nbsp;&nbsp;已关联:'+item.serviceName+ "</option>";
            	}else{
            		$html += "<option value='" + item.sellerId + "'>" + item.sellerName +'&nbsp;&nbsp;&nbsp;手机号:'+item.sellerMobile+ '&nbsp;&nbsp;&nbsp;未关联'+"</option>";
            	}
            });
            $("select[name='sellerId']").append($html);
            form.render('select','sellerIdfilter');
        }
    });
    
    $.post('/service/servicelist/list', {}, function (data) {
        var $html = "";
        if(data.data != null){
            $.each(data.data, function (index, item) {
            	$html += "<option value='" + item.serviceId + "'>" + item.serviceName + '&nbsp;&nbsp;&nbsp;手机号:'+item.servicePhone+"</option>";
            });
            $("select[name='serviceId']").append($html);
            form.render('select','serviceIdfilter');
        }
    });

    
});

/**
 * 提交保存
 */

function refFormSave(){
    let refForm = $("#refForm").serializeObject();//$.param({refState:"Y"}) + "&" + $("#refForm").serialize() + "";
    console.log('refForm--vv',refForm);
    if(refForm.sellerId != "" && refForm.serviceId != ""){
    $.post(ctx + "/service/ref/saveRef", refForm, function (data) {
        console.log('data---v',data)
        console.log('data-flag--v',data.flag)
    	if(data.flag){
	        layer.msg("保存成功", {icon: 1, time: 2000}, function(){
	        	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
	        	parent.layer.close(index); //再执行关闭
                parent.location.reload();
	        });
    	} else {
    		layer.msg(data.msg, {icon: 5}); 
    	}
    });
    }else{
    	layer.msg("请选择商户和服务商", {icon: 5}); 
    }
}